﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using EntLibContrib.Mapping.Properties;

namespace EntLibContrib.Mapping
{
  /// <summary>
  /// <para>Represents a factory for creating named instances of <see cref="IMapper"/> objects.</para>
  /// </summary>
	/// <remarks>The <see cref="LocatorNameTypeFactoryBase{T}"/> is used to improve performance in cases
	/// where objects are accessed multiple times as it searches a cache of registered objects before
	/// creating new ones</remarks>
	public class MapperProviderFactory : LocatorNameTypeFactoryBase<IMapper>
	{
		#region Construction
		/// <summary>
		/// <para>Initializes a new instance of the <see cref="MapperProviderFactory"/> class 
		/// with the default configuration source.</para>
		/// </summary>
		protected MapperProviderFactory()
			: base()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="MapperProviderFactory"/> class
		/// with the given configuration source.
		/// </summary>
		/// <param name="configurationSource">The source for configuration information.</param>
		public MapperProviderFactory(IConfigurationSource configurationSource)
			: base(configurationSource)
		{}
		#endregion

		#region Public Methods
		/// <summary>
		/// Returns an instance of <typeparamref name="T"/> based on the default instance configuration.
		/// </summary>
		/// <returns>
		/// A new instance of <typeparamref name="T"/>, or the singleton instance if <typeparamref name="T"/> allows singletons.
		/// </returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public new IMapper CreateDefault()
		{
			throw new ConfigurationErrorsException(InternalResources.ExceptionMapperNameNullOrEmpty);
		}
		#endregion
	}
}
